package rullekake.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Fakultetklasse.
 * Holder på alle data og relasjonsinformasjon for fakulteter. Består av set/get for alt + equals, hashcode og toString.
 *
 */
@Entity
@Table(name = "FACULTY")
@NamedQueries({
    @NamedQuery(name = "Faculty.findAll", query = "SELECT f FROM Faculty f"),
    @NamedQuery(name = "Faculty.findByFacultyId", query = "SELECT f FROM Faculty f WHERE f.facultyId = :facultyId"),
    @NamedQuery(name = "Faculty.findByFacultyName", query = "SELECT f FROM Faculty f WHERE f.facultyName = :facultyName"),
    @NamedQuery(name = "Faculty.findByFacultyNameNo", query = "SELECT f FROM Faculty f WHERE f.facultyNameNo = :facultyNameNo"),
    @NamedQuery(name = "Faculty.findByPhoneNumber", query = "SELECT f FROM Faculty f WHERE f.phoneNumber = :phoneNumber"),
    @NamedQuery(name = "Faculty.findByAddress", query = "SELECT f FROM Faculty f WHERE f.address = :address"),
    @NamedQuery(name = "Faculty.findByInstitution", query = "SELECT f FROM Faculty f WHERE f.institution = :institution")})
public class Faculty implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "FACULTY_ID")
    private Integer facultyId;
    @Basic(optional = false)
    @Column(name = "FACULTY_NAME")
    private String facultyName;
    @Basic(optional = false)
    @Column(name = "FACULTY_NAME_NO")
    private String facultyNameNo;
    @Column(name = "PHONE_NUMBER")
    private String phoneNumber;
    @Column(name = "ADDRESS")
    private String address;
    /*@JoinTable(name = "PERSON_FACULTY", joinColumns = {
        @JoinColumn(name = "FACULTY_ID", referencedColumnName = "FACULTY_ID")}, inverseJoinColumns = {
        @JoinColumn(name = "PERSON_ID", referencedColumnName = "PERSON_ID")})
    @ManyToMany
    private Collection<Person> personCollection;*/
    @JoinColumn(name = "INSTITUTION_ID", referencedColumnName = "INSTITUTION_ID")
    @ManyToOne(optional = false)
    private Institution institution;
    @OneToMany(mappedBy = "faculty")
    private Collection<Course> courseCollection;
    @OneToMany(mappedBy = "faculty")
    private Collection<StudyProgram> studyProgramCollection;

    public Faculty() {
    }

    public Faculty(Integer facultyId) {
        this.facultyId = facultyId;
    }

    public Faculty(Integer facultyId, String facultyName, String facultyNameNo) {
        this.facultyId = facultyId;
        this.facultyName = facultyName;
        this.facultyNameNo = facultyNameNo;
    }

    public Integer getFacultyId() {
        return facultyId;
    }

    public void setFacultyId(Integer facultyId) {
        this.facultyId = facultyId;
    }

    public String getFacultyName() {
        return facultyName;
    }

    public void setFacultyName(String facultyName) {
        this.facultyName = facultyName;
    }

    public String getFacultyNameNo() {
        return facultyNameNo;
    }

    public void setFacultyNameNo(String facultyNameNo) {
        this.facultyNameNo = facultyNameNo;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
/*
    public Collection<Person> getPersonCollection() {
        return personCollection;
    }

    public void setPersonCollection(Collection<Person> personCollection) {
        this.personCollection = personCollection;
    }
*/
    public Institution getInstitution() {
        return institution;
    }

    public void setInstitution(Institution institution) {
        this.institution = institution;
    }

    public Collection<Course> getCourseCollection() {
        return courseCollection;
    }

    public void setCourseCollection(Collection<Course> courseCollection) {
        this.courseCollection = courseCollection;
    }

    public Collection<StudyProgram> getStudyProgramCollection() {
        return studyProgramCollection;
    }

    public void setStudyProgramCollection(Collection<StudyProgram> studyProgramCollection) {
        this.studyProgramCollection = studyProgramCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (facultyId != null ? facultyId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Faculty)) {
            return false;
        }
        Faculty other = (Faculty) object;
        if ((this.facultyId == null && other.facultyId != null) || (this.facultyId != null && !this.facultyId.equals(other.facultyId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getInstitution().getInstitutionName() +" "+facultyName;
    }

}
